package com.swt.agy.backend.utils;

import org.springframework.lang.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 请填写说明
 *
 * @author sx
 * @date 2019/5/7 9:07
 */
public class StringUtils {

    /**
    * 是否数字 包括整型和浮点型
    * @param str String
    * @return boolean
    * @author sx
    * @date 2019/5/7 9:12
    */
    public static boolean isNumeric(String str){
        String reg = "^[0-9]+(.[0-9]+)?$";
        return str.matches(reg);
    }

    public static boolean isEmpty(@Nullable Object str) {
        return str == null || "".equals(str);
    }

    /**
     * 大写下划线转化为驼峰
     * @param underscoreName
     * @return
     */
    public static String camelCaseName( String underscoreName) {
        StringBuilder result = new StringBuilder();
        if (underscoreName != null && underscoreName.length() > 0) {
            underscoreName = underscoreName.toLowerCase();
            boolean flag = false;
            for (int i = 0; i < underscoreName.length(); i++) {
                char ch = underscoreName.charAt(i);
                if ("_".charAt(0) == ch) {
                    flag = true;
                } else {
                    if (flag) {
                        result.append(Character.toUpperCase(ch));
                        flag = false;
                    } else {
                        result.append(ch);
                    }
                }
            }
        }
        return result.toString();
    }


    public static boolean isHave(String[] strs,String s){
        /*此方法有两个参数，第一个是要查找的字符串数组，第二个是要查找的字符或字符串
         * */
        for(int i=0;i<strs.length;i++){
            if(strs[i].indexOf(s)!=-1){//循环查找字符串数组中的每个字符串中是否包含所有查找的内容
                return true;//查找到了就返回真，不在继续查询
            }
        }
        return false;//没找到返回false
    }

    /**
     * 去重
     * @param list
     * @return
     */
    public static List pastLeep(List list) {
        System.out.println("list = [" + list.toString() + "]");
        List listNew = new ArrayList<>();
        Set set = new HashSet();
        for (Object str : list) {
            if (set.add(str)) {
                listNew.add(str);
            }
        }
        System.out.println(listNew);
        return listNew;

    }


}
